www.gusucode.com > 用matlab gui 实现界面互相切换功能 给你带来新的方法 创建不同类型的界面源码程序 > 用matlab gui 实现界面互相切换功能 给你带来新的方法 创建不同类型的界面源码程序/tab2_main.m
function tab2_main(main_fig,ax,tab_name) % tab1_main file to set up the tab layout. % main_fig - figure handle % ax - axis handle % tab_name - is the name of the tab defined in the main file. % % The handels of the stuff in the tab are stored in the tabs % userdata. % % Dirk Tenne % CoDE (Control Dynamics and Estimation) % web: "http://code.eng.buffalo.edu" % created: "05/29/2002" % modified: "December 12. 2002" % % input treatment tab = findobj(ax,'string',tab_name); % get the handle of the tab if isempty(tab) error(['The tab with the tag ''',tab_name,' could not be found!']) else tab = get(tab,'Userdata'); % and get the handle of the tab end % look for the main figure and axis set(main_fig,'CurrentAxes',ax); pos = get(ax,'position'); txt_color = [1 1 1]; % Drawing the setup % Specifying the some positions w = 0.5*pos(3); % text box width h = 0.07*pos(4); g1 = pos(1) + w/3; g2 = pos(1) + pos(3)*3/4-w/2; h1 = pos(2) + pos(4)*.55; h2 = pos(2) + 3*h; % create the tab stuff and store it in hand hand(1:2) = inputbox([g1 h1],[0.8*w h],'kappa','tag','okappa',... 'Backgroundcolor',txt_color,... 'Callback',''); hand(3:4) = pulldown([g1 h1-3/2*h],[w h],'augmented|standard', ... 'method_1','tag','method_tab1'); callbk = ['']; hand(5:6) = pulldown([g1 h1-3*h],[w h],... 'from workspace|edit Process Noise|edit Meas. Noise',... 'Noise','tag','noise_ekf',... 'userdata',{'';'Q_okf';'R'}); set(hand(6),'callback',callbk); % log the handles of the tab1 set(hand,'Visible','off') % sets the handles initialy to off children = get(tab,'Userdata'); children.inp = hand; set(tab,'Userdata',children) function handle = inputbox(pos,siz,txt,varargin) % INPUTBOX - draws an editable text box where the txt is displayed % in front of it. w = siz(1); h = siz(2); h1 = uicontrol('style','text','string',[txt,' ='],... 'units','normalized','position',[pos .3*w h]); h2 = uicontrol('style','edit','string',txt,varargin{:},... 'units','normalized','position',[pos(1)+.3*w pos(2) 0.7*w h]); if nargout > 0 handle = [h1; h2]; end function handle = pulldown(pos,siz,opt,txt,varargin) % PULLDOWN - draws a pulldown menu with the options, where the txt % is displayed in front of it. % % handle = pulldown(pos,siz,opt,txt,varargin) % % pos - lower left corner % siz - width and hight % opt - options of the pulldown menu % txt - text to be displayed in front of the pulldown menu and name % of the pulldown menu % varargin - additional handles passed into the pulldown uicontrol % w = siz(1); h = siz(2); h1 = uicontrol('style','text','string',[txt,' ='],... 'units','normalized','position',[pos .3*w h]); callbk = ['val=get(gcbo,''value'');',... 'list=get(gcbo,''string'');',... 'assignin(''base'',''',txt,''',list(val,:));']; h2 = uicontrol('style','popup','string',opt,varargin{:},... 'units','normalized',... 'position',[pos(1)+.3*w pos(2) 0.7*w h],... 'callback',callbk); if nargout > 0 handle = [h1; h2]; end